package com.fbs.wowo.base;

/**
 * 返回给前端的封装对象
 *
 * 若成功处理请求，则返回：
 * success: true
 * message: null
 * status: 200
 * data: null或需要返回的对象或列表
 *
 * 若处理请求不成功，则返回：
 * success: false
 * message: "错误信息"
 * status: 非200
 * data: null
 *
 */
public class Response {
    private static final String STATUS_SUCCESS = "200";
    private static final String STATUS_AUTH = "403";
    private static final String STATUS_NOT_FOUND = "404";
    private static final String STATUS_ERROR = "400";

    private static final String MSG_AUTH = "无权限";

    private Boolean success = true;
    private String message = null;
    private String status = STATUS_SUCCESS;
    private Object data = null;

    public static Response success() {
        return new Response().success0();
    }
    public static Response success(Object data) {
        return new Response().success0(data);
    }

    public static Response failed(String msg) {
        return new Response().failed0(msg);
    }
    public static Response failed(String msg, String status) {
        return new Response().failed0(msg, status);
    }

    private Response failed0(String msg) {
        this.success = false;
        this.message = msg;
        this.status = STATUS_ERROR;
        this.data = null;

        return this;
    }
    private Response failed0(String msg, String status) {
        this.success = false;
        this.message = msg;
        this.status = status;
        this.data = null;
        return this;
    }

    public Response success0() {
        this.success = true;
        this.message = null;
        this.status = STATUS_SUCCESS;
        this.data = null;
        return this;
    }

    public Response success0(Object data) {
        this.success = true;
        this.message = null;
        this.status = STATUS_SUCCESS;
        this.data = data;
        return this;
    }

    public Boolean getSuccess() {
        return success;
    }

    public void setSuccess(Boolean success) {
        this.success = success;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public String getStatus() {
        return status;
    }

    public void setStatus(String status) {
        this.status = status;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

}
